function lengthOfLIS(nums) {
  // 每堆的堆顶
  const top = []
  // 牌堆数初始化为0
  let piles = 0
  for (let i = 0; i < nums.length; i++) {
      // 要处理的扑克牌
      let poker = nums[i]
      // 左堆和最又堆进行二分搜索，因为堆顶是有序排的，最终找到该牌要插入的堆
      let left = 0, right = piles
      while (left < right) {
          const mid = Math.floor((left + right) / 2)
          if (top[mid] > poker) {
              right = mid
          } else if (top[mid] < poker){
              left = mid + 1
          } else {
              right = mid
          }
      }

      //  没找到合适的牌堆，新建一堆
      if (left == piles) piles++
      // 把这张牌放到堆顶
      top[left] = poker
  }
  return piles
}

lengthOfLIS([0,3,1,6,2,2,7])

